home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
pascala.zip
/
ACK.PAS
next >
Wrap
Pascal/Delphi Source File
|
1991-05-05
|
2KB
|
65 lines
(***************************************)
(* Alejo Alamilo *)
(* COSC 055 *)
(* Spring 1990 *)
(* Acker Program *)
(***************************************)
Program Ackermann (INPUT,OUTPUT);
(*************************************************************)
(* The Ackerman function is defined recursively. *)
(* It is a function of two integer variables defined below: *)
(* Ack(M,N) = N+1 if M=0 *)
(* Ack(M,N) = Ack(M-1,1) if N=0 *)
(* Ack(M,N) = Ack(M-1,Ack(M,N-1)) otherwise *)
(*************************************************************)
VAR
M,N,I,J:INTEGER;
FUNCTION Acker(M,N:INTEGER):INTEGER;
BEGIN (* Ackerman function *)
IF M = 0 THEN
Acker:= N + 1
ELSE
IF N = 0 THEN
Acker := Acker(M-1,1)
ELSE
Acker := Acker (M-1,Acker (M,N-1))
END; (* Ackerman function *)
BEGIN (* MAIN *)
I := 0;
J := 0;
Write (' Enter in M value: ');
Readln (M);
Write (' Enter in N value: ');
Readln (N);
Writeln;
Writeln;
Writeln (' The Ackermann value for ',M:0,' and ',N:0,':');
Writeln (' N ');
Writeln (' ┌─────────────────────────────────┐');
Writeln (' │0 1 2 3 4 5 6 7 8 │');
Writeln ('M\└─────────────────────────────────┘');
While I <= N Do
BEGIN
Write (I:0,' │');
While (J <= 8) AND NOT ((J = M + 1) AND (I = N)) Do
BEGIN
Write (Acker (I,J): 4);
J := J + 1;
END;
Writeln;
J := 0;
I := I +1;
END;
END.
End;